/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package open.algo.sort;

/**
 *
 * @SortAnnoation(averageTime="o(n2)", worstTime="o(n2)", space = "o(1)", stable = true, feature= "simplest to implement")
 *
 * @author fli
 */
public class InsertSort implements Sort
{

    @Override
    public void sort(int[] a)
    {
        for (int i = 0; i < a.length; i++)
        {
            for (int j = i; j > 0 && a[j] < a[j - 1]; j--)
            {
                Swap.swap(a, j, j - 1);
            }
        }
    }

    @Override
    public String toString()
    {
        return "insertsort";
    }
}
